<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>玩家日志</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>



<form class="layui-form" action="">



  <div class="layui-form-item">
    <div class="layui-row">
    <div class="layui-col-md2">
        <select name="sid" lay-verify="required" id='server' class="layui-inline">
        <% let is_first=true;%>
        <% for(let k in ret.server ) {%>
            <% if(is_first){%>
            <option value="<%=ret.server[k].sid%>" selected><%=ret.server[k].sname%></option>
            <% is_first=false;%>
            <%}else{%>
            <option value="<%=ret.server[k].sid%>" ><%=ret.server[k].sname%></option>
            <%}%>
        <%}%>
        </select>
    </div>
    <div class="layui-col-md2">
       <input type="text" name="uid"  placeholder="请输入uid" autocomplete="off" class="layui-input layui-inline">
    </div>
    <div class="layui-col-md2">
       <input type="text" name="name"  placeholder="请输入角色名" autocomplete="off" class="layui-input layui-inline">
    </div>    
     <div class="layui-col-md3">
        <input type="text" name="event"  placeholder="事件类型" autocomplete="off" class="layui-input layui-inline">
     </div>
    <div class="layui-col-md2">
     <button class="layui-btn" lay-submit lay-filter="roleOK">立即提交</button>
    </div>
     <div class="layui-col-md3">
        <i class="layui-icon layui-icon-tips" href="http://cdn.edroity.net/doc/Log/index.html" target="_blank"></i>   
        <a href="http://dragonli.bobzuo.com/#/base/plog" target="_blank">日志类型列表</a>
     </div> 

         
  </div>
  </div>





<!--   <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="roleOK">立即提交</button>
    </div>
  </div> -->
</form>	
<table id="PlogT" lay-filter="PlogT"></table>
<button class="layui-btn" lay-submit lay-filter="forP">上一页</button>
<d id='pageIndex'>1/1</d>
<button class="layui-btn" lay-submit lay-filter="nextP">下一页</button>
<script src="/layui/layui.js"></script>
<script>
layui.config({
    base: '/webui/'  // 模块目录
}).extend({
    "cosjs":"{/}/layui/?name=cosjs",
}).use(['form','table','cosjs','element'], function () {
    let form = layui.form,cosjs=layui.cosjs,$ = layui.jquery;
    let table=layui.table;

    let page=1;
    let total=1;
    let dataRecord;


    function queryPage(_data){
      //向服务器查询
      let index=window.location.pathname.indexOf('/plog');
      let head=window.location.pathname.slice(0,index);
      let  url =`${head}/plog/query`;
      console.log(_data.field);
      cosjs.post(url,_data.field).then(ret=>{

    
        for(let k in ret.ret.rows){
          ret.ret.rows[k].all='';
          for(let j in ret.ret.rows[k]){
            if((j!='all')&&(j!='_id')&&(j!='event')&&(j!='time')&&(j!='uid')&&(j!='stime')){
               ret.ret.rows[k].all+=`${j}:${ret.ret.rows[k][j]}，`;
            }
          }
          //ret.ret.rows[k].all= JSON.stringify(ret.ret.rows[k]);
          if(ret.ret.rows[k].stime){
            ret.ret.rows[k].stime=formatDate(ret.ret.rows[k].stime);
          }
 
        }
        //table.data=_coll;

        table.render({
        elem: '#PlogT'
        ,height: 960
        ,limit:ret.ret.size
        // ,url: '/demo/table/user/' //数据接口
        ,page: false //开启分页
        ,cols: [[ //表头
          {field: 'uid', title: 'UID', width:100, sort: true, fixed: 'left'}
          ,{field: 'name', title: '角色名', width:100}
          ,{field: 'event', title: '类型', width:100}
          ,{field: 'stime', title: '时间', width:200, sort:true}
          ,{field: 'all', title: '详细', width:0, sort: false,fixed:'right'}
        ]],
        data:ret.ret.rows,
      });

      page=ret.ret.page;
      total=ret.ret.total;
      $('#pageIndex').html(page+'/'+total);
      }).catch(err=>{

        cosjs.alert(err);
      })         
    }

    form.on('submit(roleOK)', function(data){ 
      dataRecord=data;
      dataRecord.field.page=1;
      queryPage(data,page);
      return false;
    })

    form.on('submit(forP)', function(data){ 
      if(page>1){
        dataRecord.field.page=page-1;
        queryPage(dataRecord);
      }

      return false;
    })


    form.on('submit(nextP)', function(data){ 
      if(page<total){
          dataRecord.field.page=page+1;
          queryPage(dataRecord);
      }
      return false;
    })


  function formatDate(date) {
    var date = new Date(date);
    var YY = date.getFullYear() + '-';
    var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
    var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return YY + MM + DD +" "+hh + mm + ss;
  }
});
</script>
</body>
</html>